//
//  ViewController.m
//  TTScrollMenus-Demo
//
//  Created by 赵国腾 on 16/5/16.
//  Copyright © 2016年 赵国腾. All rights reserved.
//

#import "ViewController.h"
#import "TTScrollMenusView.h"
#import "TTMenu.h"

@interface ViewController ()

/** 菜单列表 */
@property (nonatomic, strong) NSArray *menus;

/**  */
@property (nonatomic, weak) IBOutlet TTScrollMenusView *scrollMenusView02;

@end

@implementation ViewController

- (NSArray *)menus {
    
    if (_menus == nil) {
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"items.plist" ofType:nil];
        NSArray *dictArray = [NSArray arrayWithContentsOfFile:path];
        
        NSMutableArray *mutaArr = [NSMutableArray array];
        for (NSDictionary *dict in dictArray) {
            [mutaArr addObject:[TTMenu menuWithDict:dict]];
        }
        _menus = mutaArr;
    }
    
    return _menus;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    TTScrollMenusView *scrollMenusView = [[TTScrollMenusView alloc] initWithFrame:CGRectMake(10, 100, 400, 200)];
    [self.view addSubview:scrollMenusView];
    scrollMenusView.dataList = self.menus;      // 配置数据源
    scrollMenusView.lineCount = 2;
    scrollMenusView.coluCount = 4;
    scrollMenusView.edgeInsets = UIEdgeInsetsMake(10, 0, 20, 0);
    
    // xib实现代码
    NSMutableArray *mutaArr = [NSMutableArray array];
    
    [mutaArr addObjectsFromArray:self.menus];
    [mutaArr addObjectsFromArray:self.menus];
    [mutaArr addObjectsFromArray:self.menus];
//    [mutaArr addObjectsFromArray:self.menus];
//    [mutaArr addObjectsFromArray:self.menus];
    self.scrollMenusView02.dataList = mutaArr;
    scrollMenusView.edgeInsets = UIEdgeInsetsMake(10, 0, 40, 0);
}

@end
